package io.github.chutian0610.sqlparser.dialect

import io.github.chutian0610.sqlparser.token.CodePoint

class PostgreSQL : Dialect {
    override fun isIdentifierPart(c: CodePoint): Boolean {
        return c.isAlphabetic() ||
                c.isAsciiDigit() ||
                CodePoint.equalsChar(c, '$') ||
                CodePoint.equalsChar(c, '_') ||
                !c.isAscii() // PostgreSQL implements Unicode characters in identifiers.
    }

    override fun isIdentifierStart(c: CodePoint): Boolean {
        return c.isAlphabetic() ||
                CodePoint.equalsChar(c, '_') ||
                !c.isAscii() // PostgreSQL implements Unicode characters in identifiers.
    }

    override fun supportsNumericLiteralUnderscores(): Boolean = true

    override fun supportsUnicodeStringLiteral(): Boolean = true

    override fun supportsStringEscapeConstant(): Boolean = true

    override fun isDelimitedIdentifierStart(c: CodePoint): Boolean = CodePoint.equalsChar(c, '"')

    /**
     * See [SQL Commands-CREATE OPERATOR](https://www.postgresql.org/docs/current/sql-createoperator.html)
     */
    override fun isCustomOperatorPart(c: CodePoint): Boolean {
        return CodePoint.inCharArray(
            c,
            '+',
            '-',
            '*',
            '/',
            '<',
            '>',
            '=',
            '~',
            '!',
            '@',
            '#',
            '%',
            '^',
            '&',
            '|',
            '`',
            '?'
        )
    }

    override fun supportsNestedComments(): Boolean = true

    override fun supportsGeometricTypes(): Boolean = true
}